import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/login/Login.vue'
import Home from '../views/home/Home.vue'
import BannerManage from '../views/bannerManage/BannerManage.vue'
import changeBanner from '../views/bannerManage/changeBanner.vue'
import GroupNews from '../views/groupNews/GroupNews.vue'
import ChangeNews from '../views/groupNews/ChangeNews.vue'
import BasicParameters from '../views/basicParameters/BasicParameters.vue'
import Column from '../views/column/Column.vue'
import ColumnSet from '../views/column/columnSet/ColumnSet.vue'
import ColumnContent from '../views/column/columnContent/ColumnContent.vue'
import AddColumn from '../views/column/addColumn/AddColumn.vue'
import IndustryManagement from '../views/industryManagement/IndustryManagement.vue'
import Add from '../views/industryManagement/add/add.vue'
import CooperativePartner from '../views/cooperativePartner/CooperativePartner.vue'
import add from '../views/cooperativePartner/add/addPartner.vue'
import Edit from "../views/cooperativePartner/edit/EditCooperative.vue"
import Editindustry from "../views/industryManagement/edit/editindustry.vue"
import BranchManage from '../views/branchManage/BranchManage.vue'
import ReportMediaManages from '../views/reportMediaManages/ReportMediaManages.vue'
import EditBranch from '../views/editBranch/EditBranch.vue'
import AddBranch from '../views/addBranch/addBranch.vue'
import AddMedia from '../views/addMedia/addMedia.vue'
import EditMedia from '../views/editMedia/EditMedia.vue'
import BusinessArea from '../views/businessArea/BusinessArea.vue'
import BackgroundUser from '../views/backgroundUser/BackgroundUser.vue'
import AddUser from '../views/backgroundUser/AddUser.vue'
import EditUser from '../views/backgroundUser/EditUser.vue'
import BranchDynamics from '../views/branchdynamics/BranchDynamics.vue'
import BranchDynamicsPop from '../views/branchdynamics_pop/BranchDynamicsPop.vue'
import BranchDynamicsEdit from '../views/branchdynamics_edit/BranchDynamicsEdit.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    redirect: '/basic',
    children: [
      {
        path: '/bannerManage',
        name: 'BannerManage',
        component: BannerManage
      }, {
        path: '/bannerManage/addBanner',
        name: 'changeBanner',
        component: changeBanner,
        props: true
      },
      {
        path: '/bannerManage/editBanner',
        name: 'changeBanner',
        component: changeBanner,
        props: true
      },
      {
        path: '/groupNews',
        name: 'GroupNews',
        component: GroupNews
      },
      {
        path: '/groupNews/addNews',
        name: 'addNews',
        component: ChangeNews,
        props: true
      },
      {
        path: '/groupNews/editNews',
        name: 'editNews',
        component: ChangeNews,
        props: true
      },
      {
        path: '/basic',
        name: 'Basic',
        component: BasicParameters
      },
      {
        path: '/column',
        name: 'Column',
        component: Column
      },
      {
        path: '/columnSet/:rowId/:parentId',
        name: 'ColumnSet',
        component: ColumnSet
      },
      {
        path: '/columnContent/:rowId',
        name: 'ColumnContent',
        component: ColumnContent
      },
      {
        path: '/addColumn',
        name: 'AddColumn',
        component: AddColumn
      },
      {
        path: '/industryManagement',
        name: 'IndustryManagement',
        component: IndustryManagement,
      },
      {
        path: '/industryManagement/add',
        component: Add,
        name: 'add'
      },
      {
        path: '/cooperativePartner',
        component: CooperativePartner,
        name: 'CooperativePartner'
      },
      {
        path: '/cooperativePartner/add',
        component: add,
        name: 'addPartner'
      },
      {
        path: '/cooperativePartner/:cooperativeId',
        component: Edit,
        name: 'EditPartner'
      },
      {
        path: '/industryManagement/:industryId',
        component: Editindustry,
        name: 'Editindustry'
      },
      {
        path: '/branchManage',
        name: 'BranchManage',
        component: BranchManage
      },
      {
        path: '/reportMediaManages',
        name: 'ReportMediaManages',
        component: ReportMediaManages
      },
      {
        path: '/editBranch',
        name: 'EditBranch',
        component: EditBranch,
        props: true

      },
      {
        path: '/editMedia',
        name: 'EditMedia',
        component: EditMedia,
        props: true
      },
      {
        path: '/addBranch',
        name: 'AddBranch',
        component: AddBranch
      },
      {
        path: '/addMedia',
        name: 'AddMedia',
        component: AddMedia
      },
      {
        path: '/businessArea',
        name: 'BusinessArea',
        component: BusinessArea
      },
      {
        path: '/backgroundUser',
        name: 'BackgroundUser',
        component: BackgroundUser
      },
      {
        path: '/addUser',
        name: 'AddUser',
        component: AddUser
      },
      {
        path: '/editUser',
        name: 'EditUser',
        component: EditUser
      },
      {
        path: '/branchDynamics',
        name: 'BranchDynamics',
        component: BranchDynamics
      },
      {
        path: '/branchdynamicsPop',
        name: 'branchdynamicsPop',
        component: BranchDynamicsPop
      },
      {
        path: '/branchdynamicsEdit/:enterpriseId',
        name: 'branchdynamicsEdit',
        component: BranchDynamicsEdit,
        props: true
      },
    ]
  }
]

const router = new VueRouter({
  routes
})


//挂载路由导航守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenstr = window.localStorage.getItem('myToken')
  if (!tokenstr) return next('/login')
  next()
})

export default router
